package com.dyp.stompwebsocket.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketStompConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //注册一个名字为"/public/server" 的endpoint,并指定 SockJS协议。
        registry.addEndpoint("/public/server").setAllowedOriginPatterns("*").withSockJS();
        registry.addEndpoint("/private/server").setAllowedOriginPatterns("*");//.withSockJS();
    }

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        // 用户订阅主题的前缀
        // /topic 代表发布广播，即群发
        // /queue 代表点对点，即发指定用户
        registry.enableSimpleBroker("/queue", "/topic", "/mass", "/single");
//        registry.setApplicationDestinationPrefixes("/first");
    }

}
